﻿using BCDto.Sim.Admin.AdminPermissionRecord;
using BCService.Sim.Admin.AdminPermissionRecord;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.Management.Admin.AdminPermission
{
    /// <summary>
    /// 员工权限记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class AdminPermissionRecordController : ManagementBaseController
    {
        private readonly IAdminPermissionRecordService adminPermissionRecordService;

        public AdminPermissionRecordController(IAdminPermissionRecordService adminPermissionRecordService)
        {
            this.adminPermissionRecordService = adminPermissionRecordService;
        }

        #region 添加员工权限记录
        /// <summary>
        /// 添加员工权限记录
        /// </summary>
        /// <param name="requestDto">员工权限</param>
        /// <response code="201">创建员工权限信息</response>
        /// <returns></returns>
        [HttpPost("[action]")]
        [Log("添加员工权限记录")]
        [ProducesResponseType(typeof(AdminPermissionRecordDto), 200)]
        public IActionResult Setting([FromBody] AdminPermissionRecordRequestDto requestDto)
        {
            var result = this.adminPermissionRecordService.Setting(requestDto);
            return Created(string.Format("/api/v1/sim/AdminPermissionRecord/{0}", result.AdminPermissionRecordId), result);
        }
        #endregion

        #region 删除员工权限
        /// <summary>
        /// 删除员工权限。
        /// </summary>
        /// <param name="staffOrganizationMappingRecordId">员工角色Id</param>
        /// <param name="operationPermission">员工权限信息</param>
        /// <response code="204">删除成功</response>
        /// <returns></returns>
        [HttpDelete("{staff_organization_mapping_record_id}/{operation_permission}")]
        [Log("删除员工权限")]
        public IActionResult Delete([FromRoute(Name = "staff_organization_mapping_record_id")]long staffOrganizationMappingRecordId, [FromRoute(Name = "operation_permission")]string operationPermission)
        {
            this.adminPermissionRecordService.Delete(staffOrganizationMappingRecordId, operationPermission);
            return this.NoContent();
        }
        #endregion

        #region 获取员工权限记录列表
        /// <summary>
        /// 获取员工权限记录列表
        /// </summary>
        /// <param name="staffOrganizationMappingRecordId">人员角色Id</param>   
        /// <response code="200">获取员工权限记录列表成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<AdminPermissionRecordDto>), 200)]
        public IActionResult List([FromQuery(Name = "staff_organization_mapping_record_id")]long staffOrganizationMappingRecordId)
        {
            var list = this.adminPermissionRecordService.GetList(staffOrganizationMappingRecordId);
            return this.Ok(list);
        }
        #endregion
    }
}